
#include "voice.h"


#define AU_AMP_SET() GPIO_SetBits(GPIOA, GPIO_Pin_12) 
#define AU_RST_SET() GPIO_SetBits(GPIOB, GPIO_Pin_11) 
#define AU_DATA_SET() GPIO_SetBits(GPIOA, GPIO_Pin_11) 
#define AU_AMP_RESET() GPIO_ResetBits(GPIOA, GPIO_Pin_12) 
#define AU_RST_RESET() GPIO_ResetBits(GPIOB, GPIO_Pin_11) 
#define AU_DATA_RESET() GPIO_ResetBits(GPIOA, GPIO_Pin_11) 


void Voice_Init(void)
{
	GPIO_InitTypeDef GPIO_InitStruct;
	
	RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA|RCC_AHBPeriph_GPIOB, ENABLE);
	GPIO_InitStruct.GPIO_Pin = /*GPIO_Pin_4|*/GPIO_Pin_11|GPIO_Pin_12;
	GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT;
	GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
	GPIO_InitStruct.GPIO_Speed =GPIO_Speed_Level_3;
	GPIO_Init(GPIOA, &GPIO_InitStruct);
	
	GPIO_InitStruct.GPIO_Pin = /*GPIO_Pin_4|*/GPIO_Pin_11;
	GPIO_Init(GPIOB, &GPIO_InitStruct);
	
}

void Speak_Vioce(uint8_t Number)
{
	uint8_t i;
	
	AU_AMP_SET();
	AU_RST_RESET();
	AU_DATA_RESET();
	
	AU_RST_SET();
	delay_ms(10);
	AU_RST_RESET();
	delay_ms(10);
	
	for(i=0;i<Number;i++)
	{
		AU_DATA_SET();
		delay_ms(1);
		AU_DATA_RESET();
		delay_ms(1);
	}
}
void Speak_Num(uint32_t num)
{
	if(num >99 || 0 == num){
		return ;
	}
	uint32_t ge = 0;
	uint32_t shi = 0;

	
	shi = num/10;
	num = num%10;
	
	ge = num;

	if(0 != shi)
	{
		Speak_Vioce(num_0+shi);
		delay_ms(300);
		Speak_Vioce(num_ten);
		delay_ms(300);
	}
	if(0 != ge)
	{
		Speak_Vioce(num_0+ge);
		delay_ms(300);
	}
	Speak_Vioce(num_port);
	delay_ms(1000);
}
void Speak_Vioce_WithNum(uint32_t num,uint32_t voice)
{
	 if(0 == num){
		 Speak_Vioce(voice);
	 }else{
		 Speak_Num(num);
		 Speak_Vioce(voice);
	 }
	 delay_ms(2000);
}
void xQueueSpeakVoice(uint8_t num ,uint8_t voice)
{
	struct t_voice msg;
	msg.num = num;
	msg.voice = voice;

	xQueueSendToBack(pQueue_Voice,(void *)&msg,0);
}

/*
void xQueueSpeakVoice(uint8_t voice)
{
	uint8_t buzzer_state = voice;
	xQueueSendToBack(pQueue_Voice,(void *)&buzzer_state,0);
}
*/



